package com.insleton.admin.user.controller;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.insleton.admin.user.model.Menu;
import com.insleton.admin.user.model.Reply;
import com.vteba.io.DefaultResourceLoader;
import com.vteba.io.Resource;
import com.vteba.io.ResourceLoader;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/menu")
public class MenuController {

    private static final Logger LOGGER = LogManager.getLogger(MenuController.class);

    @RequestMapping("/all")
    public Reply<JSONArray> all() {
        ResourceLoader loader = new DefaultResourceLoader();
        Resource resource = loader.getResource("classpath:/menus.json");
        JSONArray jsonArray = null;
        try {
            jsonArray = JSON.parseArray(resource.getInputStream());
        } catch (Exception e) {
            LOGGER.error(e);
        }

        return Reply.success("success", jsonArray);
    }

    // public static void main(String[] args) {
    //     ResourceLoader loader = new DefaultResourceLoader();
    //     Resource resource = loader.getResource("classpath:/menus.json");
    //     JSONArray jsonArray = null;
    //     try {
    //         jsonArray = JSON.parseArray(resource.getInputStream());
    //     } catch (Exception e) {
    //         LOGGER.error(e);
    //     }
    // }
}
